/*
 * File: Background.cs
 * Author: Gourav Das
 * Created: April 2011
 * Copyright: Gourav Das, 2011
 */

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using _22yards._2D;

namespace _22yards.Scenes
{
    /// <summary>
    /// This is a game Scene that implements Scene.
    /// </summary>
    public class BackgroundScene : Scene
    {

        ContentManager content;
        Texture2D backgroundTexture;

        /// <summary>
        /// Initializes a new instance of the <see cref="BackgroundScene"/> class.
        /// </summary>
        public BackgroundScene()
        {
            TransitioningTime = TimeSpan.FromSeconds(0.5);
            TransitionedTime = TimeSpan.FromSeconds(0.5);
        }


        /// <summary>
        /// Loads graphics content for this scene. The background texture can be
        /// big, so we use our own local ContentManager to load it. This allows us
        /// to unload before going from the menus into the game itself, wheras if we
        /// used the shared ContentManager provided by the Game class, the content
        /// would remain loaded forever.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(sceneEngine.Game.Services, "22yardsContent");

            backgroundTexture = content.Load<Texture2D>("TwoDEE/Screens/background");
        }


        /// <summary>
        /// Unloads graphics content for this screen.
        /// </summary>
        public override void UnloadContent()
        {
            content.Unload();
        }

        /// <summary>
        /// Updates the background scene. Unlike other scenes, this should not
        /// transition off even if it has been layered by another scene: it is
        /// supposed to be covered, after all! This overload forces the
        /// coveredByOtherScreen parameter to false in order to stop the base
        /// Update method wanting to transition off.
        /// </summary>
        public override void Update(GameTime _gameTime, bool _otherScreenHasFocus,
                                                       bool _coveredByOtherScreen)
        {
            base.Update(_gameTime, _otherScreenHasFocus, false);
        }


        /// <summary>
        /// Draws the background scene.
        /// </summary>
        public override void Draw(GameTime _gameTime)
        {
            Rectangle fullscreen = new Rectangle(0, 0, sceneEngine.GraphicsDevice.Viewport.Width, sceneEngine.GraphicsDevice.Viewport.Height);

            sceneEngine.SpriteBatch.Begin();

            sceneEngine.SpriteBatch.Draw(backgroundTexture, fullscreen,
                             new Color(TransitionAlpha, TransitionAlpha, TransitionAlpha));

            sceneEngine.SpriteBatch.End();
        }

    }
}
